package com.emily.test.service.impl;

import com.emily.test.mapper.TRoleMapper;
import com.emily.test.model.TRole;
import com.emily.test.service.RoleService;
import com.emily.test.utils.ConstentUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author ：zc
 * @date ：Created in 2019/3/8 11:35
 */
@Service(value = "role")
@Transactional(rollbackFor = {Exception.class})
public class RoleServiceImpl implements RoleService {
    @Resource
    private TRoleMapper tRoleMapper;

    @Override
    public List<TRole> selectRole() {
        return tRoleMapper.findAll();
    }

    @Override
    public TRole selectRoleById(int id) {
        return tRoleMapper.selectByPrimaryKey(id);
    }

    @Override
    public int deleteRoleById(int id) {
        return tRoleMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insertRole(TRole tRole) {
        return tRoleMapper.insert(tRole);
    }

    @Override
    public int updateRoleById(TRole tRole) {
        return tRoleMapper.updateByPrimaryKeySelective(tRole);
    }

    @Override
    public List<Map<String, Object>> selectTRoleInfoListByCompanyId(List companyIds) {
        return tRoleMapper.selectTRoleInfoListByCompanyId(companyIds);
    }

    @Override
    public int updateRoleByIds(List<TRole> tRoleList) {
        return tRoleMapper.updateRoleByIds(tRoleList);
    }

    @Override
    public List<TRole> selectRoleByCondition(TRole tRole) {
        if(!ConstentUtil.isEmpty(tRole)){
            if(ConstentUtil.isEmpty(tRole.getState())){

                return tRoleMapper.selectRoleByConditionWithOutDel(tRole);
            }else{
                return tRoleMapper.selectRoleByConditionWithInDel(tRole);
            }
        }
        return null;
    }

    @Override
    public List<TRole> selectRoleListNoResource() {
        return tRoleMapper.selectRoleListNoResource();
    }

    @Override
    public List<Map<String, Object>> selectTRoleInfoListByUserId(List list) {
        return tRoleMapper.selectTRoleInfoListByUserId(list);
    }

    @Override
    public List<TRole> selectRoleListNoMenu() {
        return tRoleMapper.selectRoleListNoMenu();
    }
}
